//app.js
App({
  onLaunch: function () {
    // 展示本地存储能力
    var logs = wx.getStorageSync('logs') || []
    logs.unshift(Date.now())
    wx.setStorageSync('logs', logs)

    // 登录
    wx.login({
      success: res => {
        // 发送 res.code 到后台换取 openId, sessionKey, unionId
      }
    })
    // 获取用户信息
    wx.getSetting({
      success: res => {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称，不会弹框
          wx.getUserInfo({
            success: res => {
              // 可以将 res 发送给后台解码出 unionId
              this.globalData.userInfo = res.userInfo

              // 由于 getUserInfo 是网络请求，可能会在 Page.onLoad 之后才返回
              // 所以此处加入 callback 以防止这种情况
              if (this.userInfoReadyCallback) {
                this.userInfoReadyCallback(res)
              }
            }
          })
        }
      }
    })
    let systemInfo = wx.getSystemInfoSync();

    //导航栏自适应

    let clientHeight = systemInfo.windowHeight;
    let clientWidth = systemInfo.windowWidth;
    let ratio = 750 / clientWidth;
    let reg = /ios/i;
    let pt = 20;//导航状态栏上内边距
    let h = 44;//导航状态栏高度
    if (reg.test(systemInfo.system)) {
      this.globalData.tabTop = systemInfo.statusBarHeight;
      this.globalData.tabbarH = 44;
    } else {
      this.globalData.tabTop = systemInfo.statusBarHeight;
      this.globalData.tabbarH = 48;
    }
    // 状态栏的高度
    let ktxStatusHeight = systemInfo.statusBarHeight * ratio
    // 导航栏的高度
    let navigationHeight = 44 * ratio
    // window的宽度
    let ktxWindowWidth = clientHeight * ratio
    // window的高度
    let ktxWindowHeight = clientHeight * ratio
    // 屏幕的高度
    let ktxScreentHeight = systemInfo.screenHeight * ratio
    // 获取tabbar高度
    let tabBarHeight = ktxScreentHeight - ktxStatusHeight - navigationHeight - ktxWindowHeight
    this.globalData.tabBarHeight = this.globalData.tabTop + this.globalData.tabbarH;
    this.globalData.screenHeight = ktxScreentHeight - this.globalData.tabBarHeight;
    this.globalData.clientHeight = clientHeight * ratio - this.globalData.tabBarHeight * 2 + tabBarHeight * 2 - 10 ;
    this.globalData.clientHeight2 = clientHeight * ratio - this.globalData.tabBarHeight * 2 - tabBarHeight * 2 + 30;
    this.globalData.clientHeight3 = clientHeight * ratio - this.globalData.tabBarHeight
    console.log( this.globalData.clientHeight);
    console.log( this.globalData.clientHeight2);
  },
  globalData: {
    userInfo: null,
    screenHeight: 0,
    tabTop: 0,
    tabbarH: 0,
    tabBarHeight: 0,
    clientHeight: 0,
    clientHeight2: 0,
    clientHeight3: 0,
    indexSearchTabs: 0,
    loginFlag:true
  }
})